package com.loong.common.executor;

import com.loong.common.function.CommonExecutor;
import com.loong.common.function.CommonSupplier;
import com.loong.common.rest.Result;
import com.loong.common.rest.rpc.RPCResponse;
import org.springframework.stereotype.Component;

@Component
public class ServiceExecutor {

    public RPCResponse execute(CommonExecutor executor) {
        executor.execute();
        return RPCResponse.success().build();
    }

    public RPCResponse execute(CommonExecutor executor, String message) {
        executor.execute();
        return RPCResponse.success().message(message).build();
    }

    public RPCResponse execute(CommonSupplier executor, String message) {
        return RPCResponse.success().data(executor.get()).message(message).build();
    }

    public RPCResponse execute(CommonSupplier executor) {
        return RPCResponse.success().data(executor.get()).build();
    }
}
